package com.kyb.cms.module.config.web.rpc;

import com.kyb.cms.util.LoginCookieUtil;
import com.kyb.cms.util.LoginUser;
import lombok.extern.slf4j.Slf4j;
import org.armada.galileo.annotation.mvc.NoToken;
import org.armada.galileo.common.util.CommonUtil;
import org.armada.galileo.exception.BizException;
import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;

/**
 * @author xiaobo
 * @date 2023/11/6 14:31
 */
@Slf4j
@Controller
public class UserRpc {

    @NoToken
    public void login(String user, String pwd, HttpServletResponse response) {

        if (!"admin".equals(user)) {
            throw new BizException("用户名或密码不正确");
        }

        String s = "kyb_" + CommonUtil.format(new Date(), "MMddHH");

        log.info("new pwd: " + s);

        if (!s.equals(pwd)) {
            throw new BizException("用户名或密码不正确");
        }

        LoginUser loginUser = new LoginUser();
        loginUser.setLoginId("1")
                .setUserName("admin")
                .setAvatarUrl("")
                .setUserId(1L);

        LoginCookieUtil.setLoginData(loginUser, response);

    }
}
